package com.wy.entity.bean;

public class Page {

	private Integer currPage = 1;
	private Integer totalPage;
	private Integer totalRecord;
	private Integer pageSize = 3;
	private Integer startRow = 0;
	
	/** constructor */
	public Page(){
		
	}
	public Page(Integer totalRecord, Integer currPage){
		this.setTotalRecord(totalRecord);
		this.setCurrPage(currPage);
	}

	//计算
	public void setTotalRecord(Integer totalRecord) {
		this.totalRecord = totalRecord;
		//1.得到总记录数，计算总页数
		if(totalRecord > 0){
			if(totalRecord < pageSize){
				totalPage = 1;
			}else if(totalRecord % pageSize > 0){
				totalPage = (totalRecord / pageSize) + 1;
			}else {
				totalPage = totalRecord / pageSize;
			}
		}else{
			totalPage = 0;
		}
	}
	public void setCurrPage(Integer currPage) {
		this.currPage = currPage;
		//2.得到当前页，计算起始和结束记录数
		if(totalPage == 0 || currPage <= 0){
			startRow = 0;
		}else if(currPage < totalPage){
			startRow = (currPage - 1) * pageSize;
		}else{
			startRow = (totalPage - 1) * pageSize;
		}
	}
	
	/** getter and setter */
	public Integer getCurrPage() {
		return currPage;
	}
	public Integer getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	public Integer getTotalRecord() {
		return totalRecord;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getStartRow() {
		return startRow;
	}
	public void setStartRow(Integer startRow) {
		this.startRow = startRow;
	}
	
	
}
